package jmm;

import lombok.extern.java.Log;
import org.openjdk.jol.info.ClassLayout;

/**
 * @ClassName jmm05
 * @date 2021/4/2 18:38
 * @Version 1.0
 * @Description //模拟轻量级锁升级为重量级锁
 * @USER root
 */
@Log
public class jmm05 {

    public static void main(String[] args) throws InterruptedException {
            Thread.sleep(5000);
            Object a = new Object();

            Thread thread1 = new Thread(()->{
                synchronized (a) {
                    log.info("thread1 locking");
                    log.info(ClassLayout.parseInstance(a).toPrintable());
                    try {
                        Thread.sleep(2000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            },"thread1");
        Thread thread2 = new Thread(()->{
            synchronized (a) {
                log.info("thread2 locking");
                log.info(ClassLayout.parseInstance(a).toPrintable());
                try {
                    Thread.sleep(2000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        },"thread2");
        thread1.start();
        thread2.start();
    }
}
